﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;

namespace BerkeleyAlgorithm
{

    class ElectionProccess
    {
        public string UUID;
        private string HighestUUID;
        private NeighbourTable table;
        System.Threading.Thread[] newThreads;
        bool isMyUUIDTheBiggest;

        public ElectionProccess(NeighbourTable table, System.Threading.Thread[] threads)
        {
            this.table = table;
            UUID = Guid.NewGuid().ToString();
            newThreads = threads;
            HighestUUID = "";
            isMyUUIDTheBiggest = false;
        }



        public void startElections()
        {
            //add timer?
            broadCast("ElectionsStarted;" + UUID); //'secret' msg
        }



        public void broadCast(string str)
        {
            tcpClient cli;
            foreach (Neighbour n in table.Neighbours)
            {
                if (!n.Address.ToString().Equals(utils.FindLanAddress().ToString()))
                {
                    cli = new tcpClient(n.Address, n.Port);
                    cli.sendMsg(str);
                }
            }
        }

    }
}
